// app.js
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
     
    //初始化云开发
    if (wx.cloud) {
      // console.log("有云开发")
      wx.cloud.init({
        env:'cloud1-3gdxc6rr1dff5ed9',
        traceUser: true
      })
    }
    if(wx.getStorageSync("userInfo")){
      
      this.globalData.userId = JSON.parse(wx.getStorageSync("userInfo")).userId
      // console.log(this.globalData.userId)
    }
    wx.getSystemInfo({
      success: e => {
        this.globalData.StatusBar = e.statusBarHeight;
        let capsule = wx.getMenuButtonBoundingClientRect();
		if (capsule) {
		 	this.globalData.Custom = capsule;
			this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
		} else {
			this.globalData.CustomBar = e.statusBarHeight + 50;
		}
      }
    })
  },


  //监听音乐播放
  watch: function (method) {
    var obj = this.globalData
    Object.defineProperty(obj, 'songInfo', {
      configurable: true,
      enumerable: true,
      set: function (value) {
        this._name = value;
        method(value);
      },
      get: function(){
        return this._name
      }
     })
  },

  
  watchplay: function (method) {
    var obj = this.globalData
    Object.defineProperty(obj, 'isMusicPlay', {
      configurable: true,
      enumerable: true,
      set: function (value) {
        this._name = value;
        method(value);
      },
      get: function(){
        return this._name
      }
     })
  },

  globalData: {
    userId:null,
    playList:[],
    userInfo: null,
    songInfo: null,
    backgroundAudioManager : wx.getBackgroundAudioManager(),
    isMusicPlay:false,
    playorder:'icon-xunhuanbofang',  //控制播放顺序 icon-xunhuanbofang:循环播放 icon-suijibofang_ ：随机播放 icon-danquxunhuan1 ：单曲循环
    
  }
})
